/*
* Copyright (c) 2012 Kyle Hayward
* 
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* 
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#pragma once

namespace OptixDotNet 
{
	/// <summary>
	/// Represents PTX compiled CUDA code. Enables run-time compiling of CUDA source on developer workstations.
	/// </summary>
	public ref class CompiledCuda
	{
	public:

		/// <summary>
		/// Saves the compiled PTX to 'path'.
		/// </summary>
		/// <param name="path">Path of the file to save the PTX to.</param>
		void Save( System::String^ path );

		/// <summary>
		/// Compiles a CUDA (.cu) source file to PTX. You must have the path to optix and cuda setup in your System path.
		/// <para>Requirements:</para>
		/// <para>You must have Visual Studio 2008 or 2010 installed (along with the CUDA and Optix SDKs).</para>
		/// You must have the paths to CUDA and Optix C include folders in your path (or define these using the preprocessor arguments).
		/// </summary>
		/// <remarks>
		/// Makes a system call to NVCC which in turn uses Visual Studio's cl to compile the CUDA programs to PTX.
		/// </remarks>
		/// <param name="fileName">Path of the CUDA source file.</param>
		/// <param name="preprocessorArgs">Array of preprocessor arguments.</param>
		static CompiledCuda^ CompileFromFile( System::String^ fileName, array<System::String^>^ preprocessorArgs );

		/// <summary>
		/// Compiles a CUDA (.cu) source string to PTX. You must have the path to optix and cuda setup in your System path.
		/// <para>Requirements:</para>
		/// <para>You must have Visual Studio 2008 or 2010 installed (along with the CUDA and Optix SDKs).</para>
		/// You must have the paths to CUDA and Optix C include folders in your path (or define these using the preprocessor arguments).
		/// </summary>
		/// <remarks>
		/// Makes a system call to NVCC which in turn uses Visual Studio's cl to compile the CUDA programs to PTX.
		/// </remarks>
		/// <param name="source">String containing CUDA source.</param>
		/// <param name="preprocessorArgs">Array of preprocessor arguments.</param>
		static CompiledCuda^ CompileFromString( System::String^ source, array<System::String^>^ preprocessorArgs );

		/// <summary>
		/// Gets the compiled PTX string.
		/// </summary>
		property System::String^ Compiled
		{
			System::String^ get() { return mCompiledSource; }
		}

	internal:
		CompiledCuda( const char* compiledSource );

		static CompiledCuda^ Compile( System::String^ source, array<System::String^>^ preprocessorArgs, bool fromFile );

	private:
		CompiledCuda() { }

	private:
		System::String^ mCompiledSource;

	};
}